"""
@File    : xl_02.py
@Author  : sharan
@Time    : 2020/12/20 14:36
@Desc    :
"""
import xlwings as xw

# wb = xw.Book(r'D:\test_1.xlsx')
# print(wb)

""" 句柄app"""
app = xw.App(visible=True, add_book=False)
app.display_alerts = False
app.screen_updating = True

""" 建立连接实例
    wb对应一个Excel文件
"""
# file_path_1 = r'D:\test_1.xlsx'
# wb = app.books.open(file_path_1)
# wb.save()
# wb.close()
# app.quit()

""" 新建excel"""
# file_path_3 = r'D:/test_3.xlsx'
# 新建Excel
# wb_create = app.books.add()
# wb_create.save(file_path_3)
# wb_create.close()
# app.quit()

""" 单元格输入内容"""
file_path_3 = r'D:/test_3.xlsx'
# wb_insert = app.books.open(file_path_3)
wb_read = xw.Book(file_path_3)
sht_0 = wb_read.sheets[0]
info = sht_0.used_range
nrows = info.last_cell.row
print(nrows)
ncolumns = info.last_cell.column
print(ncolumns)

# wb_insert.sheets['sheet1'].range('A1').value = [['Foo 1', 'Foo 2', 'Foo 3'], [10.0, 20.0, 30.0]]
# wb_insert.save()
# print(wb_insert.sheets['test'].range('A1').expand().value)
# 新建sheet
# wb_insert.sheets.add("test")
# wb_insert.sheets['test'].range('A1').value = '苦短'
# wb_insert.save()

""" 获取Excel 值"""
# file_path_3 = r'D:/test_3.xlsx'
# wb_read = app.books.open(file_path_3)
# a1 = wb_read.sheets[0].range('A1').value
# print(a1)
# a2 = wb_read.sheets[0].range(2, 2).value
# print(a2)












